package com.hzit.order.config;

import com.hzit.order.properties.HzitThreadPoolProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 类名：
 * 作者：WF
 * 功能：
 */
@Configuration
@EnableConfigurationProperties(HzitThreadPoolProperties.class)
public class HzitThreadPool {

	@Bean
	public ThreadPoolExecutor threadPoolExecutor(HzitThreadPoolProperties properties){
		return new ThreadPoolExecutor(properties.getCoreSize(),
				properties.getMaxSize(),
				properties.getKeepAliveTime(),
				TimeUnit.SECONDS,
				new LinkedBlockingQueue<>(properties.getQueues()),
				Executors.defaultThreadFactory(),
				new ThreadPoolExecutor.AbortPolicy());
	}
}
